home *** CD-ROM | disk | FTP | other *** search
-
- The following is a complete description of closures and templates.
-
- The term UNIT refers to a closure that contains the free variables of a
- compiled expression produced by ORBIT.
-
- An object whose header is a template is said to be a closure over that template.
-
- There are two kinds of templates: those internal to a code-vector (bytev)
- and those internal to a closure (unit).
-
- Templates contain the following information and accessors:
-
- pointer and scratch slots (unsigned)
- These give the number of pointer (rootable) and scratch (non-rootable)
- slots in closures over this template. They are accessable by the primops
- TEMPLATE-POINTER-SLOTS and TEMPLATE-SCRATCH-SLOTS.
- If the closure is internal to a closure then these two fields are adjoind to
- get the offset of the closure in its surrrounding closure.
-
- number of arguments (signed)
- If this field is 0, the closure is not callable
- If it is > 0, it may be called and the field is 1 + the number of args
- expected by the procedure
- If it is < 0, it is a return point and the field is minus (1 + the number of
- args expected)
- Accessable with TEMPLATE-NARGS
-
- nary?
- Specifies whether the closure is nary (lexpr)
-
- handler-offset (signed)
- Given a template, this field is added (sign extended) to the pointer to get
- the address of the handler code for the closure. If this field is 0
- there is no handler.
-
- code-vector-offset (unsigned)
- This subtracted (zero extended) from a template gives the code vector.
-
- annotation offset
- This gives the offset in the UNIT of the vcell corresponding to a defined
- procedure. If this closure is not lexicaly inferior to a defined procedure
- then this field is 0.
-
- H-bit
- This is on if the closure is in the heap
- Access with TEMPLATE-HEAPED-BIT?
-
- I-bit
- This is on if the closure is internal to another closure (see closure section)
- Access with TEMPLATE-INTERNAL-BIT?
-
- S-bit
- This is on if the closure is a continuation and is inferior to another
- continuation
-
- This is what a template (internal to a code vector) looks like:
-
- (VAX)
-
- ------------------------------------------------------------------
- | handler offset | annotation offset |S|H|I|
- ------------------------------------------------------------------
- | pointer | scratch | code vector offset |
- ------------------------------------------------------------------
- | <---------- code | nargs |?| template |
- ---------------------------------
- ^ ^
- | |
- | ----------- nary bit
- |
- ----------------------------- template pointer
-
- (M68)
-
-
- ------------------------------------------------------------------
- | annotation offset |S|H|I| handler offset |
- ------------------------------------------------------------------
- | pointer | scratch | code vector offset |
- ------------------------------------------------------------------
- |T|?| | nargs | code ----------->
- ----------------------------------
- ^ ^ ^
- | |-------- nary bit |
- | |
- |----------- template bit |
- ----------------------------- template pointer
-
-
- If the first instruction in code is the jump absolute instruction
- then the template is internal to the unit and looks like
-
- (VAX)
-
- ------------------------------------------------------------------
- | pointer | scratch | offset of template in unit|00|
- ------------------------------------------------------------------
- | jump absolute instruction | nargs |?| template |01|
- ------------------------------------------------------------------
- | address of auxiliary template |10|
- ------------------------------------------------------------------
-
- (M68)
-
- ------------------------------------------------------------------
- | pointer | scratch | offset of template in unit |
- ------------------------------------------------------------------
- |T|?| | nargs | jump absolute instruction |
- ------------------------------------------------------------------
- | address of auxiliary template |
- ------------------------------------------------------------------
-
-
- The auxiliary template is a normal template. When the closure is called
- control is transferred to the auxiliary template. When operation dispatch
- is attempted on the closure, the auxiliary template is used to get the handler.
-
-
- Closures
-
- Closures are either stand-alone or internal to another closure
- If it is internal to another closure then pointer and scratch information is
- not relevant but we need to know the address of the surrounding closure.
- The offset is the pointer and scratch slots adjoined
- There is a restriction that the templates of a closure internal closure
- must be internal to a code vector, not the unit.
-
- (RISC) Little endian
-
- ------------------------------------------------------------------
- | handler offset | annotation offset |S|H|I|
- ------------------------------------------------------------------
- | code vector offset |
- ------------------------------------------------------------------
- | pointer | nargs |?| template |
- ------------------------------------------------------------------
- ^ ^
- | |
- | ----------- nary bit
- |
- ----------------------------- template pointer
-
- ------------------------------------------------------------------
- | offset of template in unit |00|
- ------------------------------------------------------------------
- | pointer | 0 |?| template |01|
- ------------------------------------------------------------------
- | address of auxiliary template |10|
- ------------------------------------------------------------------
-